﻿namespace Canteen.Core.Models
{
    public class Result : HttpResult<object> { }
    public class HttpResult<T>
    {
        public int Code { get; set; } = 0;
        public T Data { get; set; } = default;
        public string Message { get; set; }

        public HttpResult() { }
        public HttpResult(int code, T data) { Code = code; Data = data; }
        public HttpResult(int code, T data, string message) : this(code, data) { Message = message; }

        public static HttpResult<T> Instance { get { return new HttpResult<T>(); } }
        public static HttpResult<T> Success()
        {
            return new HttpResult<T>
            {
                Data = default
            };
        }
        public static HttpResult<T> Success(T data)
        {
            return new HttpResult<T>
            {
                Data = data
            };
        }
        public static HttpResult<T> Fail(string message)
        {
            return new HttpResult<T>
            {
                Code = 1,
                Message = message
            };
        }
        public static HttpResult<T> Fail(int code, string message)
        {
            return new HttpResult<T>
            {
                Code = code,
                Message = message
            };
        }
    }
}
